package com.haitai.solr.resp;

import java.io.Serializable;

/**
 * 统一响应规范类
 */
public class RespData<T> implements Serializable {

    private static final long serialVersionUID = 7176479465492389672L;

    /**
     * 请求结果状态码 调用是否成功,success 表示成功,fail表示失败
     */
    private String stateCode;

    /***
     *  失败错误码
     */
    private String errorCode;
    /**
     * 错误描述
     */
    private String errorDesc;
    /**
     * 数据
     */
    private Object data;

    public String getStateCode() {
        return stateCode;
    }

    public void setStateCode(String stateCode) {
        this.stateCode = stateCode;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorDesc() {
        return errorDesc;
    }

    public void setErrorDesc(String errorDesc) {
        this.errorDesc = errorDesc;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * 成功返回结果
     *
     * @param data
     * @return
     */
    public static RespData successRsp(Object data) {
        RespData resp = new RespData();
        resp.setData(data);
        resp.setStateCode(RespConstant.SUCCESS);
        return resp;
    }

    public static RespData successRsp() {
        RespData resp = new RespData();
        resp.setStateCode(RespConstant.SUCCESS);
        return resp;
    }

    public static RespData failRsp(String errorCode, String errorDesc) {
        RespData resp = new RespData();
        resp.setStateCode(RespConstant.FAIL);
        resp.setErrorCode(errorCode);
        resp.setErrorDesc(errorDesc);
        return resp;
    }

    /**
     * 失败返回结果
     *
     * @param data
     * @return
     */
    public static RespData failRsp(String errorCode, String errorDesc, Object data) {
        RespData resp = new RespData();
        resp.setData(data);
        resp.setStateCode(RespConstant.FAIL);
        resp.setErrorCode(errorCode);
        resp.setErrorDesc(errorDesc);
        return resp;
    }

    @Override
    public String toString() {
        return "RespData{" +
                "stateCode='" + stateCode + '\'' +
                ", errorCode='" + errorCode + '\'' +
                ", errorDesc='" + errorDesc + '\'' +
                ", data=" + data +
                '}';
    }
}
